using System;
using System.Collections.Generic;
using System.Text;
using DAO;
using DTO;
using System.Data;
namespace BUS
{
    public enum TheLoaiSachBUSResult
    {
        OK ,
        DAOERROR
    }
    public class TheLoaiSach
    {
        public static TheLoaiSachBUSResult SelectAll(List<DTO.TheLoaiSach> ds)
        {
            string sql = "select * from TheLoaiSach";
            DAO.Interface dao = new DAO.TheLoaiSach();
            DataTable dt = dao.Select(sql);
            if (dt != null)
            {
                for (int i = 0 ; i < dt.Rows.Count ; i++)
                {
                    DTO.TheLoaiSach temp = new DTO.TheLoaiSach();
                    temp.MaTheLoai = dt.Rows[i].ItemArray[0].ToString();
                    while (temp.MaTheLoai.IndexOf(" ") >= 0)
                        temp.MaTheLoai = temp.MaTheLoai.Replace(" " , "");
                    temp.TenTheLoai = dt.Rows[i].ItemArray[1].ToString();
                    ds.Add(temp);
                }
                return TheLoaiSachBUSResult.OK;
            }
            return TheLoaiSachBUSResult.DAOERROR;
        }

        public static bool Insert(string sql)
        {
            DAO.TheLoaiSach tls = new DAO.TheLoaiSach();
            return tls.Insert(sql);
        }
        public static bool Update(string sql)
        {
            DAO.TheLoaiSach tls = new DAO.TheLoaiSach();
            return tls.Update(sql);
        }
        public static bool Delete(string sql)
        {
            DAO.TheLoaiSach tls = new DAO.TheLoaiSach();
            return tls.Delete(sql);
        }
        public static DataTable Select(string sql)
        {
            DAO.TheLoaiSach tls = new DAO.TheLoaiSach();
            return tls.Select(sql);
        }
        public static string LayMaTheLoai(string tenTheLoai)
        {
            DAO.TheLoaiSach tls = new DAO.TheLoaiSach();
            return tls.LayMaTheLoai(tenTheLoai);
        }
    }
}
